package com.rfsp.common.pojo.bo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.rfsp.common.enums.SystemConst;

public class Result {
	public static String EVENT_SUCCESS="success";
	public static String EVENT_FAIL="fail";
	private String target="";
	private String action="";
	private String event="";
	private String tips="";
	private String totalTips="";
	private Map<String,Object> data=new HashMap<String,Object>();
	private Integer total=0;
	private List<Map<String,Object>> rows=null;
	private List<Result> resultList=new ArrayList<Result>();
	
	public String getTarget() {
		return target;
	}
	public void setTarget(String target) {
		this.target = target;
	}
	public String getAction() {
		return action;
	}
	public void setAction(String action) {
		this.action = action;
	}
	public String getEvent() {
		return event;
	}
	public void setEvent(String event) {
		this.event = event;
	}
	public String getTips() {
		return tips;
	}
	public void setTips(String tips) {
		this.tips = tips;
	}
	public Map<String, Object> getData() {
		return data;
	}
	public void setData(Map<String, Object> data) {
		this.data = data;
	}
	public Integer getTotal() {
		return total;
	}
	public void setTotal(Integer total) {
		this.total = total;
	}
	public List<Map<String, Object>> getRows() {
		return rows;
	}
	public void setRows(List<Map<String, Object>> rows) {
		this.rows = rows;
	}
	
	public List<Result> getResultList() {
		return resultList;
	}
	public void setResultList(List<Result> resultList) {
		this.resultList = resultList;
	}
	public void setDataByTotalRows(Long total,List<Map<String, Object>> rows){
		//Map<String,Object> data=new HashMap<String,Object>();
		if(total==0L){
			this.setEvent(SystemConst.EVENT_NODATA);
			this.setTips(SystemConst.TIPS_NODATA);
		}
		data.put("total", total);
		data.put("rows", rows);
		this.setData(data);
	}
	public Map<String,Object> toMap(){
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("target", this.getTarget());
		map.put("action", this.getAction());
		map.put("event", this.getEvent());
		map.put("tips", this.getTips());
		map.put("data", this.getData());
		map.put("errors", new ArrayList());
		return map;
	}
	
	public String getTotalTips() {
		return totalTips;
	}
	public void setTotalTips(String totalTips) {
		data.put("totalTips", totalTips);
		this.totalTips = totalTips;
	}
	public String getResultListTips(){
		StringBuffer sb=new StringBuffer();
		
		for(int i=0;i<resultList.size();i++){
			if(i>0){
				sb.append("\n");
			}
			sb.append(resultList.get(i).getTips());
		}
		return sb.toString();
	}
}
